//package com.qiaofang.common.utils;
//
//import com.google.gson.Gson;
//import com.qiaofang.common.exception.SystemException;
//import com.qiniu.common.Zone;
//import com.qiniu.http.Response;
//import com.qiniu.storage.Configuration;
//import com.qiniu.storage.UploadManager;
//import com.qiniu.util.Auth;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.multipart.MultipartFile;
//
//@Slf4j
//public class QiniuUtil {
//
//    public static String accessKey = "19MWcvu_DQadEbW2U-_DwNd_VYS2nHmiHVeRMyJd";
//    public static String secretKey = "41pEzhttF3vOiCSKy257h-WWmU7VmC9vbveUo4of";
//    public static String baseUrl = "http://image.qfstatic.com/";
//    public static String bucket = "qiaofang";
//    public static String uploadDirPrefix = "biz/img/";
//
//    public static Zone zone = Zone.autoZone();
//
//    public static Configuration config = new Configuration(zone);
//    public static UploadManager uploadManager = new UploadManager(config);
//
//    /**
//     * 单文件简单上传操作
//     */
//    public static String upload(MultipartFile file) {
//        try {
//            //调用put方法上传
//            log.info("file size :" + file.getSize());
//            Response res = uploadManager.put(file.getBytes(), uploadDirPrefix + System.currentTimeMillis() + file.getOriginalFilename(), createUploadToken(bucket));
//            Gson gson = new Gson();
//            QiniuResult q = gson.fromJson(res.bodyString(), QiniuResult.class);
//            return baseUrl + q.getKey();
//        } catch (Exception e) {
//            log.error("上传7牛报错", e);
//            throw new SystemException("上传7牛报错");
//        }
//    }
//
//    public static String createUploadToken(String bucket) {
//        return Auth.create(accessKey, secretKey).uploadToken(bucket);
//    }
//}